package com.yuke.cloud.service.omc.payUtil;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConstants;
import com.alipay.api.DefaultAlipayClient;

/**
 * 创建时间：2016年11月10日 下午7:09:08
 * <p>
 * alipay支付
 *
 * @author andy
 * @version 2.2
 */

public class Alipayutil {


    public static String NOTIFYURL = "http://my-domain.ngrok.weigankeji.com/order/pay/notify";
    public static final String ALIPAY_APPID = "2018101061646066"; // appid
    // app支付私钥
    public static String APP_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7sbRE3xgzrzidHpslCu9LkFOn9mjbAhrNlG8W1qmolz6RGPxm8e65V3A5YgQZfiXeoS/jXCEHDVqIP6FO2JGDQ6gpcl150YGOnZPsMfmAqHiNsxAuRcerokTY/KZxrtBgZPgDWIWMEuB0jlZ5IQY0W7Xix7EMyWi9Od57bMKCz2h+x+OyxyO9kTZrDzwwWV6v/hublfZ2fGHKDh3bQd+5gSV40JfCX2joH6pmgYVp6F14UJHT9R7Cx69iwQdWnVog21FIi5KDMkvSomEvS+WSTdWY0ryxo+3tCPcSkAneVr6RMKcu4w7t34FLTEgtwVistduLaQAsawBahgD117TNAgMBAAECggEBAIuOmQQwgVVErqqcrCzB0aV0vc8Ad3yINxeui18G44U4V8wZMOr2blMfAZGZIIU3975uSSYbRW9x7WOrNCxk+OUJ9EpE/93o+hTpc6hGjEaufVyWzKwrNEiY0eopCTU0DzntOT97nWjGTGA9yWwtMujRXA8v/aQNSbSRB6zr9EC/4vAZ5iC9QDDZ1ONU0turtSKsyPBOu7GzRsCTS19uTX0hGGYMlkjvyA3fhcxgBNwuvg6stfL0B2Mc3YmSR1mEiVq3Ay6cs3BbHJkA3+nDL7rsnSm3hKOIp/mNoWhKAHWyuMfBtxuAykZDWKgalklPi69WYkzLbV2/zUOKFp/kMCECgYEA24p3POToTlzpcd5aVnLkuXo0DLjwTgL0ri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ecD5JFRgYnD6Ti+u9P/qeGoSdQrCTT51gRl62ZLSTFOQ/H/eFTt5ic9APODyA+xq4VbW40myoVcx5cZQW/Trfpb9cdMgX/ah9jr3V9dMQ+HCvIIRKMCClE+AfmllSQObUW5Fxx8UQ+phVt0ZWini2RPu9b3SwBQhDYLUIDH4xRmplE4QIDAQAB";

  /*  static {
        try {
            Resource resource = new ClassPathResource("alipay_private_key_pkcs8.pem");
           // APP_PRIVATE_KEY = FileUtil.readInputStream2String(resource.getInputStream());
            resource = new ClassPathResource("alipay_public_key.pem");
           // ALIPAY_PUBLIC_KEY = FileUtil.readInputStream2String(resource.getInputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

    // 统一收单交易创建接口
    private static AlipayClient alipayClient = null;

    public static AlipayClient getAlipayClient() {
        if (alipayClient == null) {
            synchronized (Alipayutil.class) {
                if (null == alipayClient) {
                    alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", ALIPAY_APPID,
                            APP_PRIVATE_KEY, AlipayConstants.FORMAT_JSON, AlipayConstants.CHARSET_UTF8,
                            ALIPAY_PUBLIC_KEY, AlipayConstants.SIGN_TYPE_RSA2);
                }
            }
        }
        return alipayClient;
    }
}